package case4

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Test() {
	fmt.Println("🎯案例四：Gin渲染 HTML渲染")

	r := gin.Default()

	// Gin框架中使用LoadHTMLGlob()或者LoadHTMLFiles()方法进行HTML模板渲染。
	r.LoadHTMLGlob("templates/**/*")

	r.GET("/posts/index", func(c *gin.Context) {
		c.HTML(http.StatusOK, "posts/index.html", gin.H{
			"title": "posts/index",
		})
	})

	r.GET("/users/index", func(c *gin.Context) {
		c.HTML(http.StatusOK, "users/index.html", gin.H{
			"title": "users/index",
		})
	})

	// 启动
	r.Run(":60000")
}
